package com.example.day02.Custom;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.example.day02.R;

@SuppressLint("AppCompatCustomView")
public class FrameImageView extends ImageView {
    Paint paint;
    public FrameImageView(Context context) {
        super(context);
    }

    public FrameImageView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        //获取布局当中设置的属性
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.FrameImageView);
       int color= typedArray.getColor(R.styleable.FrameImageView_boundcolor,Color.BLACK);
       float size=typedArray.getDimensionPixelSize(R.styleable.FrameImageView_boundsize,20);
        paint = new Paint();
        paint.setColor(color);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(size);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Rect rect=canvas.getClipBounds();
        rect.right--;
        rect.bottom--;

        canvas.drawRect(rect,paint);
    }
}
